package org.zhxy.core.system.controller;


import org.springframework.web.bind.annotation.*;
import org.zhxy.common.aop.AutomaticLog;
import org.zhxy.common.config.ServiceFactory;
import org.zhxy.common.response.Result;
import org.zhxy.common.response.ResultCode;
import org.zhxy.entity.system.Role;

import java.util.Map;

@RestController
@RequestMapping("/role")
public class RoleController {

    @RequestMapping(value = "/getRoleList",method = RequestMethod.POST)
    public Result getRoleList(@RequestBody Map<String,Object> map){
        return new Result(ResultCode.SUCCESS_NO_MESSAGE, ServiceFactory.roleService.getRoleList(map));
    }

    @AutomaticLog("保存角色")
    @RequestMapping(value = "/saveRole",method = RequestMethod.POST)
    public Result saveRole(@RequestBody Role role){
        return ServiceFactory.roleService.saveRole(role);
    }

    @AutomaticLog("修改角色")
    @RequestMapping(value = "/updateRole",method = RequestMethod.POST)
    public Result updateRole(@RequestBody Role role){
        return ServiceFactory.roleService.updateRole(role);
    }

    @AutomaticLog("删除角色")
    @RequestMapping(value = "/removeRole/{id}",method = RequestMethod.GET)
    public Result removeRole(@PathVariable("id")String id){
        return ServiceFactory.roleService.removeRole(id);
    }

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public Result findAll(){
        return new Result(ResultCode.SUCCESS_NO_MESSAGE,ServiceFactory.roleService.findAll());
    }

    @AutomaticLog("保存或修改教师的角色，可多选")
    @RequestMapping(value = "/saveOrUpdateUserRole",method = RequestMethod.POST)
    public Result saveOrUpdateUserRole(@RequestBody Map<String, Object> map){
        return ServiceFactory.roleService.saveOrUpdateUserRole(map);
    }
}
